from datetime import date
from extensions import db

# ------------------------------------------------------------------
# 1 员工基本信息
# ------------------------------------------------------------------
class EmployeeBasicInfo(db.Model):
    __tablename__ = 'employee_basicinfo'
    employee_id = db.Column(db.String, primary_key=True)
    name = db.Column(db.String)
    former_name = db.Column(db.String)
    gender = db.Column(db.String)
    nation = db.Column(db.String)
    political_status = db.Column(db.String)
    native_place = db.Column(db.String)
    birth_place = db.Column(db.String)
    birth_date = db.Column(db.Date)
    full_time_edu = db.Column(db.String)
    full_time_degree = db.Column(db.String)
    part_time_edu = db.Column(db.String)
    part_time_degree = db.Column(db.String)
    party_join_date = db.Column(db.Date)
    league_join_date = db.Column(db.Date)
    hire_date = db.Column(db.Date)
    health_status = db.Column(db.String)
    id_card = db.Column(db.String, unique=True)
    professional_title = db.Column(db.String)
    unit = db.Column(db.String)
    department = db.Column(db.String)
    position = db.Column(db.String)
    recruitment_detail = db.Column(db.String)
    cylc_join_detail = db.Column(db.String)
    cpc_join_detail = db.Column(db.String)
    other_party_join_detail = db.Column(db.String)
    skills_achievements_detail = db.Column(db.String)
    overseas_activity_detail = db.Column(db.String)
    foreign_lang_detail = db.Column(db.String)
    minority_lang_detail = db.Column(db.String)
    hobby_detail = db.Column(db.String)

    # 反向关系
    training_records = db.relationship('TrainingRecord', backref='employee', cascade='all, delete-orphan')
    reward_records = db.relationship('RewardRecord', backref='employee', cascade='all, delete-orphan')
    punishment_records = db.relationship('PunishmentRecord', backref='employee', cascade='all, delete-orphan')
    club_records = db.relationship('ClubParticipationRecord', backref='employee', cascade='all, delete-orphan')
    family_members = db.relationship('FamilyMemberInfo', backref='employee', cascade='all, delete-orphan')
    social_relationships = db.relationship('SocialRelationshipInfo', backref='employee', cascade='all, delete-orphan')
    spouse = db.relationship('SpouseInfo', backref='employee', uselist=False, cascade='all, delete-orphan')
    edu_experiences = db.relationship('EducationExperience', backref='employee', cascade='all, delete-orphan')
    position_changes = db.relationship('PositionChangeRecord', backref='employee', cascade='all, delete-orphan')
    salary_adjustments = db.relationship('SalaryAdjustmentRecord', backref='employee', cascade='all, delete-orphan')
    work_experiences = db.relationship('WorkExperience', backref='employee', cascade='all, delete-orphan')
    meeting_records = db.relationship('MeetingAttendanceRecord', backref='employee', cascade='all, delete-orphan')
    title_records = db.relationship('ProfessionalTitleRecord', backref='employee', cascade='all, delete-orphan')

# ------------------------------------------------------------------
# 2 培训记录
# ------------------------------------------------------------------
class TrainingRecord(db.Model):
    __tablename__ = 'training_record'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), nullable=False)
    begin_date = db.Column(db.Date)
    detail = db.Column(db.Text)

# ------------------------------------------------------------------
# 3 奖励记录
# ------------------------------------------------------------------
class RewardRecord(db.Model):
    __tablename__ = 'reward_record'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), nullable=False)
    award_date = db.Column(db.Date)
    detail = db.Column(db.Text)

# ------------------------------------------------------------------
# 4 处分记录
# ------------------------------------------------------------------
class PunishmentRecord(db.Model):
    __tablename__ = 'punishment_record'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), nullable=False)
    punishment_date = db.Column(db.Date)
    detail = db.Column(db.Text)

# ------------------------------------------------------------------
# 5 社团参与记录
# ------------------------------------------------------------------
class ClubParticipationRecord(db.Model):
    __tablename__ = 'club_participation_record'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), nullable=False)
    join_date = db.Column(db.Date)
    detail = db.Column(db.Text)

# ------------------------------------------------------------------
# 6 家庭成员
# ------------------------------------------------------------------
class FamilyMemberInfo(db.Model):
    __tablename__ = 'family_member_info'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), nullable=False)
    relation = db.Column(db.String)
    name = db.Column(db.String)
    birth_date = db.Column(db.Date)
    political_status = db.Column(db.String)
    work_unit = db.Column(db.Text)

# ------------------------------------------------------------------
# 7 社会关系
# ------------------------------------------------------------------
class SocialRelationshipInfo(db.Model):
    __tablename__ = 'social_relationship_info'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), nullable=False)
    relation = db.Column(db.String)
    name = db.Column(db.String)
    birth_date = db.Column(db.Date)
    political_status = db.Column(db.String)
    work_unit = db.Column(db.Text)

# ------------------------------------------------------------------
# 8 配偶信息
# ------------------------------------------------------------------
class SpouseInfo(db.Model):
    __tablename__ = 'spouse_info'
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), primary_key=True)
    relation = db.Column(db.String)
    name = db.Column(db.String)
    birth_date = db.Column(db.Date)
    political_status = db.Column(db.String)
    work_unit = db.Column(db.Text)
    professional_title = db.Column(db.String)
    nation = db.Column(db.String)
    native_place = db.Column(db.String)
    start_work_date = db.Column(db.Date)
    education = db.Column(db.String)
    degree = db.Column(db.String)
    salary = db.Column(db.Integer)

# ------------------------------------------------------------------
# 9 教育经历
# ------------------------------------------------------------------
class EducationExperience(db.Model):
    __tablename__ = 'education_experience'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), nullable=False)
    enrollment_date = db.Column(db.Date)
    graduation_date = db.Column(db.Date)
    graduation_status = db.Column(db.String)
    school = db.Column(db.String)
    college = db.Column(db.String)
    major = db.Column(db.String)
    witness_name = db.Column(db.String)

# ------------------------------------------------------------------
# 10 职位变动记录
# ------------------------------------------------------------------
class PositionChangeRecord(db.Model):
    __tablename__ = 'position_change_record'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), nullable=False)
    change_date = db.Column(db.Date)
    department = db.Column(db.String)
    position = db.Column(db.String)
    reporting_unit = db.Column(db.String)
    reporting_unit_seal_date = db.Column(db.Date)
    approval_unit_seal_date = db.Column(db.Date)
    admin_unit_seal_date = db.Column(db.Date)

# ------------------------------------------------------------------
# 11 薪资调整记录
# ------------------------------------------------------------------
class SalaryAdjustmentRecord(db.Model):
    __tablename__ = 'salary_adjustment_record'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), nullable=False)
    adjustment_date = db.Column(db.Date)
    department = db.Column(db.String)
    position_level = db.Column(db.Integer)
    salary_level = db.Column(db.Integer)
    salary_point = db.Column(db.Integer)
    salary = db.Column(db.Integer)

# ------------------------------------------------------------------
# 12 工作经历
# ------------------------------------------------------------------
class WorkExperience(db.Model):
    __tablename__ = 'work_experience'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), nullable=False)
    start_date = db.Column(db.Date)
    end_date = db.Column(db.Date)
    work_unit = db.Column(db.String)
    position = db.Column(db.String)
    witness = db.Column(db.String)

# ------------------------------------------------------------------
# 13 会议参加记录
# ------------------------------------------------------------------
class MeetingAttendanceRecord(db.Model):
    __tablename__ = 'meeting_attendance_record'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), nullable=False)
    attendance_date = db.Column(db.Date)
    meeting_name = db.Column(db.String)
    position = db.Column(db.String)

# ------------------------------------------------------------------
# 14 职称获取记录
# ------------------------------------------------------------------
class ProfessionalTitleRecord(db.Model):
    __tablename__ = 'professional_title_record'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.String, db.ForeignKey('employee_basicinfo.employee_id'), nullable=False)
    acquisition_date = db.Column(db.String)
    detail = db.Column(db.Text)